<template>
  <div class="wrap-product-banner">
<!--    :autoplay="{ delay: 5000,disableOnInteraction: false}"-->
    <swiper
      :slidesPerView="1"
      :spaceBetween="0"
      :loop="true"
      :centeredSlides="true"
      :autoplay="{ delay: 15000,disableOnInteraction: false}" :pagination="customPagination"  :navigation="true" :modules="modules" class="mySwiper">
      <swiper-slide v-for="(item, index) in homeBanner">
        <div class="swiper-item">
          <i class='picture_url' :style="'background-image:url('+item.pictureUrl+')'"></i>
        </div>
        <div class="swiper-info" v-if="route.name !=='product'">
          <span class="title">{{item.advName}}</span>
          <span class="detail">{{item.remark}}</span>
        </div>
      </swiper-slide>
<!--      <div class="swiper-pagination"></div>-->
<!--      <template #container-start>-->
<!--        <button class="nav-button-prev" :disabled="vSwiperIndex === 0" @click="prevVSwiperSlide">-->
<!--          <i class="iconfont icon-arrow-down"></i>-->
<!--        </button>-->
<!--      </template>-->
<!--      <template #container-end>-->
<!--        <button class="nav-button-next" :disabled="vSwiperIndex === 5 - 1" @click="nextVSwiperSlide">-->
<!--          <i class="iconfont icon-arrow-up"></i>-->
<!--        </button>-->
<!--      </template>-->
    </swiper>
    <div class='product-content' v-if="route.name =='product'">
      <div class='left-con'>
        <div class='left-item'>
          <img src='../../../public/img/AppIcon.png' class='app_icon' alt=''>
          <p class='title'>睐回APP</p>
          <p class='info'>二奢行家，睐回逛逛</p>
        </div>
        <div class='right-img'>
          <img src='../../../public/img/appView.png' class='app_view' alt=''>
        </div>
        <div class='bottom-con'>
          <ul>
            <li class='item-list' v-for='(item,index) in appList' :key='index' :class="{'active':currentIndex===index&&item.isShow}" @click='toggleQrCode(item,index)'>
              <i :class='item.icon'></i><span>{{item.name}}</span>
              <div class='popup-view' :style="{'display':item.isShow?'flex':'none'}" >
                <div class='list'>
                  <img :src="item.qrCode" alt=''>
                  <span>{{item.hint}}</span>
                </div>
              </div>
            </li>
            <!--          <li class='item-list'><i class='app_Android_icon'></i><span>Android</span></li>-->
            <!--          <li class='item-list'><i class='app_webChat_icon'></i><span>小程序</span></li>-->
          </ul>
        </div>
      </div>

    </div>
  </div>
</template>

<script setup lang='ts'>
import {defineProps, ref, onMounted,reactive} from "vue";
import type SwiperClass from 'swiper'
import {Swiper, SwiperSlide} from 'swiper/vue'; // swiper所需光伏组件
// 这是分页器和对应方法，swiper好像在6的时候就已经分离了分页器和一些其他工具
import {Autoplay, Navigation, Pagination, A11y} from 'swiper';
// 引入swiper样式，对应css 如果使用less或者css只需要把scss改为对应的即可
import 'swiper/css';
import 'swiper/css/navigation';
import 'swiper/css/pagination';
import home from '@/assets/ts/home/home'
import { AdResponseData ,ADFormData,AppResponseData} from '@/api/home/type'
import { getAdvertisementList,getAppList } from '@/api/home'
import { useRoute, useRouter } from 'vue-router'
import setting from '@/setting'
// import useDeviceInfo from "@/hooks/deviceInfo"
import { useDeviceInfo } from "@/hooks/deviceInfo"
const {    DeviceType, getDeviceInfo} = useDeviceInfo()
const router = useRouter()
const route = useRoute()
let deviceObj: object = ref({})
onMounted(() => {
  getAdList()
  getAppListData()
  deviceObj = getDeviceInfo()
  console.log(DeviceType,'看看',getDeviceInfo())
})


//获取广告列表
const homeBanner = ref<any>(home.homeBannerList)
// const homeBanner = ref<any>([]);
async function getAdList() {
  console.log('route',route)
  let params ={
    position:route.name=='home'?1:route.name=='product'?2:3
  }
  let res: AdResponseData = await getAdvertisementList(params)
  console.log('res',res)
  homeBanner.value = res.data
}

const bulletRenderer = (index: number, className: string) => {
  console.log(index,className)
  const _className = `${className} swiper-pagination-bullet-custom`
  return `<span class="${_className}">${index + 1}</span>`
}
const customPagination = {
  clickable: true,
  // renderBullet: bulletRenderer,
  // type: 'custom',
  // renderCustom: function (swiper, current, total) {
  //   console.log(swiper,current,total)
  //   return current + ' of ' + total;
  // }
}


const countdownRef = ref(null);

/*@swiper="onSwiper"*/
const onSwiper = (swiperInstance) => {
  resetCountdownPosition(swiperInstance);
  swiperInstance.on('slideChange', () => {
    console.log("切换图片了")
    resetCountdownPosition(swiperInstance);
  });
};

const resetCountdownPosition = (swiperInstance) => {
  console.log("当前元素", countdownRef.value.style.transform)
  countdownRef.value.style.transform = 'translateX(-0%)';
  /*  countdownRef.value.style.width = '50%'*/
};
const onSlideChange = e => {
  // swiper切换的时候执行的方法
  console.log('slide change', e.activeIndex);
};

const modules = [Autoplay, Pagination, Navigation, A11y];


// eslint-disable-next-line vue/no-setup-props-destructure
// const props = defineProps({
//   picList: {
//     type: Array,
//     required: true,
//     default: () => []
//   }
// });





const handleHSwiperReady = (swiper: SwiperClass) => {
  console.log('SwiperComponentReady!', swiper)
}
const handleHSwiperSlideChange = (swiper: SwiperClass) => {
  console.log('handleHSwiperSlideChange!', swiper.realIndex)
}
const clickedMap = reactive(new Map<number, boolean>())
const isSlideClicked = (id: number) => clickedMap.get(id)
const handleHwiperSlideClick = (id: number) => {
  clickedMap.set(id, true)
  console.log('Click slide! target slide id:', id)
}

// vertical swiper
let vSwiperRef: SwiperClass | null = null
// const setVSwiperRef = (swiper: SwiperClass) => {
//   vSwiperRef = swiper
// }
const vSwiperIndex = ref<number>()
const updateVSwiperIndex = () => {
  vSwiperIndex.value = vSwiperRef?.activeIndex
}
const prevVSwiperSlide = () => vSwiperRef?.slidePrev()
const nextVSwiperSlide = () => vSwiperRef?.slideNext()

let appList =ref([])
async function getAppListData() {
  let res: AppResponseData = await getAppList()
  console.log('app-res',res)
  let {data} =res
  console.log(data)
let datas = data.map(item =>{
    return{
      name:item.versionName,
      clientType:item.clientType,
      icon:item.clientType==='0'?'app_iPhone_icon':item.clientType==='1'?'app_Android_icon':'app_webChat_icon',
      qrCode:item.downloadUrl,
      hint:item.remark,
      isShow:false
    }
  })
 appList.value =datas
}
const currentIndex = ref(-1)

/**
 * 打开二维码或者处理跳转对应下载页
 * @param items
 * @param index
 */
function toggleQrCode(items:object,index){
  if(DeviceType.value=='手机'){
    handleSkip(items.clientType)
  }else if(DeviceType.value=='电脑'){
    currentIndex.value = index
    appList.value.map((item) => {
      if (items.name === item.name) {
        item.isShow = !item.isShow
      } else {
        item.isShow = false
      }
    })
  }else{//平板
    handleSkip(items.clientType)
  }

}

/**
 * 移动端模式，按照点击客户端类型进行跳转
 * @param clientType
 */
function handleSkip(clientType) {
  switch (clientType) {
    case '0'://    苹果
        router.push({ path: '/download' ,params:{link:0}})
      break;
    case '1'://      安卓
      router.push({ path: '/download' ,params:{link:1}})
      break;
    case '3'://微信小程序
      window.location.href =setting.wechatAppletURLScheme
      break;
  }
}

</script>
<style scoped lang='scss'>
i.picture_url {
  transition: all 0.3s ease;
  object-fit: cover;
  width: 100%;
  height: 815px;
  background-position: center;
  background-size: cover;
  background-repeat: no-repeat;
  display: block;
}
.swiper-info{
  position: absolute;
  display: flex;
  flex-direction: column;
  align-items: baseline;
  font-family: PingFangSC, PingFang SC;

  color: #FFFFFF;
  line-height: 73px;
  letter-spacing: 6px;
  text-align: left;
  font-style: normal;
  width: 1200px;
  margin-left: 42px;
  bottom: 226px;
  .title{
    font-weight: 600;
    font-size: 52px;
  }
  .detail{
    font-weight: 400;
    font-size: 28px;
    color: #FFFFFF;
    line-height: 40px;
    letter-spacing: 5px;
  }
}
::v-deep .swiper-pagination-horizontal.swiper-pagination-bullets .swiper-pagination-bullet {
  border-radius: inherit;
  width: 100%;
  height: 2px;
  margin: 0px !important;
  position: relative;
  &::after{
    content: "";
    width: 2px;
    height: 9px;
    display: block;
    position: absolute;
    right: -2px;
    background-color: #fff;
    top: -3px;

  }
  &::before{
    content: "";
    width: 2px;
    height: 9px;
    display: block;
    position: absolute;
    left: -1;
    background-color: #fff;
    top: -3px;

  }
  &:first-child:before{
    display: none;
  }
  &:last-child:after{
    display: none;
  }
}
::v-deep .swiper-pagination .swiper-pagination-bullet.swiper-pagination-bullet-active {
  background-color: rgb(255, 29, 29) !important;
}
::v-deep .swiper-pagination {
  position: absolute;
  text-align: center;
  transition: 0.3s opacity;
  z-index: 10;
  width: 60.76%;
  display: flex;
  left: 40%;
  transform: translate(-44%, 59%);
  bottom: 89px;
}
</style>
<style scoped>
.mySwiper {
  width: 100%;
  height: 100%;
}
.mySwiper img {
  width: 100%;
  height: 100%;
  object-fit: cover;
}

.swiper-item {
  transition: all 0.3s ease;
  width: 100%;
  height: 100%;
  display: flex;
  flex-direction: column;
  align-items: center;
}

.swiper-item > img {
  transition: all 0.3s ease;
  object-fit: cover;
  width: 100%;
  height: 815px;
  background-position: center;

}

.swiper-slide {
  text-align: center;
  font-size: 18px;
  background: #fff;

  /* Center slide text vertically */
  display: -webkit-box;
  display: -ms-flexbox;
  display: -webkit-flex;
  display: flex;
  -webkit-box-pack: center;
  -ms-flex-pack: center;
  -webkit-justify-content: center;
  justify-content: center;
  -webkit-box-align: center;
  -ms-flex-align: center;
  -webkit-align-items: center;
  align-items: center;
}



:deep(.swiper-pagination) .swiper-pagination-bullet.swiper-pagination-bullet-active {
  background-color: rgb(255, 255, 255);

}

:deep(.swiper-pagination-bullet) {
  width: 10px;
  height: 10px;
  background-color: #fff;
}

.swiper-horizontal > .swiper-pagination-bullets .swiper-pagination-bullet,
:deep(.swiper-pagination-horizontal.swiper-pagination-bullets) .swiper-pagination-bullet {
  margin: 0 8px;
}


:deep(.swiper-button-prev),
:deep(.swiper-button-next) {
  transition: all 0.3s ease;
  transform: scale(0.85);
  margin: 0 36px;

  opacity: 0;
  color: #fff;

}

.mySwiper:hover :deep(.swiper-button-prev) {
  opacity: 1;
}

.mySwiper:hover :deep(.swiper-button-next) {
  opacity: 1;
}



@keyframes moveCountdown {
  0% {
    transform: translateX(-100%);
  }
  100% {
    transform: translateX(0);
  }
}


@media screen  and (max-width: 767px) {
  /*.swiper-item {*/
  /*  height: 100%;*/
  /*}*/

  /*.swiper-item > img {*/
  /*  height: 100%;*/
  /*}*/

}

</style>
<style lang="scss" scoped>
::v-deep .swiper-button-prev {
  position: absolute;
  left: 77%;
  top: 86%;
  opacity: 1;
  &::after{
    width: 14px !important;
    height: 26px !important;
    font-size: 20px;
  }
  &:hover{
    opacity: 1;
    color: rgba(255, 29, 29, 1);
  }
}

::v-deep .swiper-button-next {
  position: absolute;
  left: 80%;
  top: 86%;
  opacity: 1;
  &::after{
    width: 14px !important;
    height: 26px !important;
    font-size: 20px;
  }
  &:hover{
    opacity: 1;
    color: rgba(255, 29, 29, 1);
  }
}
.wrap-product-banner{
  height: 100%;
  width: 100%;
  position: relative;
  .product-content {
    position: absolute;
    width: 1200px;
    display: flex;
    justify-content: space-between;
    margin-top: 147px;
    top: 0%;
    left: 50%;
    transform: translate(-50%, 0%);
    z-index: 99;
    .left-con {
      display: flex;
      justify-content: space-between;
      width: 100%;
      flex-wrap: wrap;
      .left-item {
        margin-left: 47px;
        img.app_icon{
          margin-top: 61px;
          height: 135px;
          width: 135px;
        }
        p.title {
          font-family: PingFangSC, PingFang SC;
          font-weight: 600;
          font-size: 47px;
          color: #FFFFFF;
          line-height: 66px;
          text-align: left;
          font-style: normal;
          margin-top: 39px;
        }

        p.info {
          font-family: PingFangSC, PingFang SC;
          font-weight: 100;
          font-size: 28px;
          color: #FFFFFF;
          line-height: 40px;
          letter-spacing: 5px;
          text-align: left;
          font-style: normal;
        }
      }
      .right-img {
        margin-right: 47px;
        img.app_view{
          width: 510px;
          height: 535px;
          transform: scale(1);
          transition: all 0.3s;
        }
      }
      .bottom-con {
        position: relative;
        top: -150px;
        left: 47px;
        ul{
          display: flex;
          flex-wrap: wrap;
          width: 100%;
          justify-content: space-around;
          li.item-list{
            background: rgba(255,255,255,0.2);
            border: 1px solid #FFFFFF;
            //opacity: 20%;
            width: 150px;
            height: 46px;
            font-family: PingFangSC, PingFang SC;
            font-weight: 400;
            font-size: 16px;
            color: #FFFFFF;
            line-height: 22px;
            text-align: left;
            font-style: normal;
            display: flex;
            justify-content: center;
            align-items: center;
            margin-right: 19px;
            position: relative;
            margin-bottom: 20px;
            &:last-child{
              margin-right: 0;
            }
            i{
              background-repeat: no-repeat;
              background-position: center;
              background-size: contain;
              display: block;
              width: 22px;
              height: 22px;
              margin-right: 10px;
            }
            i.app_iPhone_icon{
              background-image: url("../../../public/img/apple.png");
            }
            i.app_Android_icon{
              background-image: url("../../../public/img/Android.png");
            }
            i.app_webChat_icon{
              background-image: url("../../../public/img/webchat.png");
            }
            &:hover,&.active{
              background: #FFFFFF;
              color: #000000;
              i.app_iPhone_icon{
                background-image: url("../../../public/img/black_apple.png");
              }
              i.app_Android_icon{
                background-image: url("../../../public/img/black_android.png");
              }
              i.app_webChat_icon{
                background-image: url("../../../public/img/black_webchat.png");
              }

            }
            &:hover{
              .popup-view{
                display: flex!important;
              }
            }
            .popup-view{
              position: absolute;
              width: 134px;
              height: 135px;
              background-color: #FFFFFF !important;
              top: 64px;
              left: 50%;
              transform: translate(-50%, 0%);
              z-index: 9;
              cursor: unset;
              //display: flex;
              align-items: center;
              justify-content: center;
              //transition: transform 0.25s ease-out, opacity 0.25s ease-out;
              transition: all 0.3s;
              .list{
                display: flex;
                flex-direction: column;
                align-items: center;
                position: relative;
                >img {
                  width: 91px;
                  height: 91px;

                }
                span{
                  font-family: PingFangSC, PingFang SC;
                  font-weight: 400;
                  font-size: 12px;
                  color: #000000;
                  line-height: 17px;
                  letter-spacing: 1px;
                  text-align: left;
                  font-style: normal;
                  padding-top: 4px;
                }
              }
              //三角形
              &::before {
                content: "";
                position: absolute;
                top: -9px;
                width: 0;
                height: 0;
                border-left: 8px solid transparent;
                border-right: 8px solid transparent;
                border-bottom: 10px solid white;
              }
            }
          }
        }
      }
    }

  }
}

</style>
